﻿@{
    ViewBag.Title = "FindAdjPrice";
}

@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script> 
}

<form id="form1" runat="server">
    <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;">                
          <table style="width:100%;">
            <td style="width:100%;">
                <a class="mini-button" iconCls="icon-ok" onclick="onOk" plain="true">选择</a>
                <span class="separator"></span>
                <a class="mini-button" iconCls="icon-new" onclick="onRefresh" plain="true">刷新</a>
                <span class="separator"></span>
                <a class="mini-button" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
            </td>
        </table>                
    </div>
    <div>
        <table style="margin-bottom:4px;">
            <tr>
                <td width ="80px" align="right">
                    单据日期：</td>
                <td width ="180px">
                    @Html.Partial("~/Views/Modular/dxDateRange.cshtml") 
                </td>
                <td width ="80px" align="right">
                    单据编号：</td>
                <td width ="150px">
                    <input name="FBillNo" class="mini-textbox" style="width:150px;" onkeypress="setkeyPress()"/></td>
                <td width ="80px" align="right">
                    名称搜索：</td>
                <td width ="150px">
                    <input name="FName" class="mini-textbox" style="width:150px;" onkeypress="setkeyPress()"/></td>
            </tr>
        </table>
        <table style="height: 430px;width:750px">
            <tr>
                <td>   
                    <div class="mini-splitter" style="width:890px;height:430px;">
                        <div size="46%" showCollapseButton="true" style="padding:1px;">
                             <div id="gridleft" class="mini-datagrid" style="width:100%;height:97%;" 
                                  idField="id" showFooter="false" allowSortColumn="false"pageSize="12"
                                  showPager = "true" showPageSize="true" showPageIndex="true" showReloadButton ="false"
                                  allowCellSelect="true" allowCellEdit="true" onselectionchanged="onSelectionChanged" 
                                  selectOnLoad="true"fitColumns="false"onrowdblclick="onOk"
                                  url="../Bill/GetBillQuery">
                                  <div property="columns">
                                      <div type="checkcolumn" ></div>
                                      <div field="FBillNo" name="FBillNo" width="130px" headerAlign="center">单据编号</div>  
                                      <div field="FDate" name="FDate" width="90px" dateFormat="yyyy-MM-dd" headerAlign="center">开单日期</div>
                                      <div field="FName" name="FName" width="150px" headerAlign="center">名称</div>
                                  </div>               
                             </div>
                        </div>
                        <div showCollapseButton="true">
                            <div id="gridmain" class="mini-datagrid" style="width:100%;height:97%;"pageSize="15"  
                                idField="id" showFooter="true" fitColumns="false"
                                showPager = "false" showPageSize="false" showPageIndex="true" 
                                allowCellSelect="true" allowCellEdit="true"
                                url="../Bill/GetBillQueryDetail">
                                <div property="columns"> 
                                    <div type="indexcolumn" width="35" headerAlign="center" >序号</div>
                                    <div field="FNumber" name="FNumber" width="80" headerAlign="center">商品编码</div>
                                    <div field="FName" name="FName" width="130" headerAlign="center">商品名称</div>
                                    <div field="FUnitName" name="FUnitName" width="40" headerAlign="center">单位</div>
                                    <div field="mFPrice" name="mFPrice" width="60" headerAlign="center"align="right"numberFormat="#,0.00">单价</div>
                                    <div field="mFQty" name="mFQty" width="60" headerAlign="center"align="right" numberFormat="#,0.00"  summaryType="sum">新价</div>  
                                    <div field="mFAmount" name="FAmount" width="60" headerAlign="center"align="right"numberFormat="#,0.00"  summaryType="sum">差价</div> 
                                </div>             
                            </div>        
                        </div>  
                    </div>    
                 </td>             
            </tr>
        </table>
    </div>

     <script type="text/javascript">
         mini.parse();
         var bKind = "0";
         var uID = parent.window.getSystemAppID();
         var sumFields = "";
         var grid1 = mini.get("gridleft");
         var grid2 = mini.get("gridmain");

         ////////////////////
         //标准方法接口定义
         function SetData(data) {
             bKind = data.BillKind;
             onRefresh();
         }

         function FormShown() {
             var nowDate = new Date();
             mini.getbyName("FDate1").setValue(nowDate);
             mini.getbyName("FDate2").setValue(nowDate);
         }

         function setkeyPress() {
             if (event.keyCode == 13) {
                 onRefresh();
             }
         }

         function onRefresh() {
             var st = mini.getbyName("FDate1").getFormValue();
             var en = mini.getbyName("FDate2").getFormValue();
             var billno = mini.getbyName("FBillNo").getValue();
             var sName = mini.getbyName("FName").getValue();
             var json = "[{";
             json = json + "'FBillType':'" + bKind + "',";
             json = json + "'FName':'" + sName + "',";
             json = json + "'FBillNo':'" + billno + "',";
             json = json + "'FDate1':'" + st + "',";
             json = json + "'FDate2':'" + en + "',";
             json = json + "'FSystemAppID':'" + uID + "'}]";
             grid2.setData(null);
             grid1.load({ mdatajson: json });
         }

         function onSelectionChanged(e) {
             var grid = e.sender;
             var record = grid.getSelected();
             if (record) {
                 grid2.load({ BillType: bKind, mBillID: record.KInterID, mSystemAppID: uID });
             }
             else {
                 grid2.setData(null);
             }
         }

         function onDrawSummaryCell(e) {
             var result = e.result;
             var grid = e.sender;
             var rows = e.data;

             if (sumFields != "") {
                 if (sumFields.indexOf(e.field) >= 0) {
                     var total = 0;
                     for (var i = 0, l = rows.length; i < l; i++) {
                         var row = rows[i];
                         var t = row[e.field];
                         if (isNaN(t)) continue;
                         total += parseFloat(t);
                     }
                     total = total.toFixed(2);
                     e.cellStyle = "text-align:right";
                     e.cellHtml = total;
                 }

             }
         }

         function onOk() {
             var rec = grid1.getSelected();
             if (rec) {
                 CloseWindow(rec);
             }
         }

     </script>
  </form>